// 文件路径: dbms/common/Constants.java
package com.dbms.common;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * 一个中央常量类，用于存放整个项目中共享的静态常量值。
 * 这样做的好处是便于管理和修改，避免在代码中散落“魔法值”。
 *
 * 【已修改】
 * 新增了用于定义外键约束的 `FOREIGN`, `KEY`, `REFERENCES` 关键字。
 */
public class Constants {
    // 定义数据库中每个页面的大小为 4KB (4096字节)。
    public static final int PAGE_SIZE = 4096;

    // 使用一个Set集合存储所有的SQL关键字。Set提供了高效的`contains`检查，便于词法分析器快速识别关键字。
    public static final Set<String> KEYWORDS = new HashSet<>(Arrays.asList(
            "SELECT", "FROM", "WHERE", "CREATE", "TABLE", "INSERT", "INTO",
            "VALUES", "DELETE", "INT", "VARCHAR", "PRIMARY", "KEY",
            "UPDATE", "SET", "JOIN", "ON", "ORDER", "GROUP", "BY", "ASC", "DESC",
            "BACKUP", "DATABASE", "TO", "USER", "IDENTIFIED", "DROP",
            "GRANT", "REVOKE", "BEGIN", "TRANSACTION", "COMMIT", "ROLLBACK",
            "EXPLAIN", "ANALYZE", "LIMIT", "HAVING",
            "FOREIGN", "REFERENCES" // 【新增】外键相关关键字
    ));

    // 定义支持的SQL数据类型常量。
    public static final String TYPE_INT = "INT";
    public static final String TYPE_VARCHAR = "VARCHAR";

    // 定义支持的SQL运算符集合。
    public static final Set<String> OPERATORS = new HashSet<>(Arrays.asList(
            "+", "-", "*", "/", "=", ">", "<", ">=", "<=", "!=", "<>"
    ));

    // 定义SQL中的分隔符集合。
    public static final Set<Character> DELIMITERS = new HashSet<>(Arrays.asList(
            ',', ';', '(', ')', '.', '[', ']'
    ));

    // 定义不同SQL语句类型的内部标识符常量。这些常量在解析后用于标识语句的类型。
    public static final String STATEMENT_CREATE_TABLE = "CREATE_TABLE";
    public static final String STATEMENT_INSERT = "INSERT";
    public static final String STATEMENT_SELECT = "SELECT";
    public static final String STATEMENT_DELETE = "DELETE";
    public static final String STATEMENT_BACKUP = "BACKUP";
    public static final String STATEMENT_UPDATE = "UPDATE";
    public static final String STATEMENT_CREATE_USER = "CREATE_USER";
    public static final String STATEMENT_DROP_USER = "DROP_USER";
    public static final String STATEMENT_GRANT = "GRANT";
    public static final String STATEMENT_REVOKE = "REVOKE";
    public static final String STATEMENT_BEGIN_TRANSACTION = "BEGIN_TRANSACTION";
    public static final String STATEMENT_COMMIT = "COMMIT";
    public static final String STATEMENT_EXPLAIN = "EXPLAIN";
    public static final String STATEMENT_ROLLBACK = "ROLLBACK";

    /**
     * 定义一个错误类型枚举。
     * 用于在编译器的不同阶段（词法、语法、语义分析）对错误进行分类，
     * 以便生成更精确的错误报告。
     */
    public enum ErrorType {
        LEXICAL_ERROR,   // 词法错误 (e.g., 非法字符)
        SYNTAX_ERROR,    // 语法错误 (e.g., 关键字顺序错误)
        SEMANTIC_ERROR   // 语义错误 (e.g., 查询不存在的表)
    }
}